package practiceProjects;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @Project ：learn_java
 * @File ：AddWordInRime4Huma.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/3/24 21:24
 * @Description ：win11添加自定义词组到rime虎码词库
 */

public class AddWordInRime4Huma4cmd {

    public static boolean isValidLowerCase(String input) {
        // 正则表达式：匹配1个或多个小写字母
        return input != null && input.matches("^[a-z]+$");
    }

    public static void main(String[] args) {
        String path = "C:\\Users\\zhq11\\AppData\\Roaming\\Rime\\tigress.extended.dict.yaml";

        Scanner sc = new Scanner(System.in);
        System.out.println("input phrase:");
        String s = sc.nextLine().trim();
        System.out.println("input code (0 < len <= 4):");
        String code = sc.nextLine().trim();

        if (!isValidLowerCase(code) || code.isEmpty() || code.length() > 4) {
            System.out.println("invalid input, check your input.");
            return;
        }

        String newPhrase = s + "\t" + code + "\t1000";

        // 默认权重1000，即最高
        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(path, true)))) {
            out.println(newPhrase);
            System.out.println("add successful");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
